package com.qf.om.servlet;

import com.qf.om.entity.Student;
import com.qf.om.myutils.DataUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/addstudent")
public class AddStudentServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决乱码
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        String sex = req.getParameter("sex");

        //校验
        Student student = new Student();
        student.setName(name);
        student.setAge(age);
        student.setSex(sex);
        //保存数据 - 数据库 - List模拟
        DataUtils.addStudent(student);
        resp.sendRedirect("addstudent.jsp?status=1");
    }

}
